<meta charset="UTF-8">
<script type="text/javascript">
$(function(){
	$('#ClassGradebtn').bind('click',function(){
			var bjId2=$('#Classtb').combobox('getValue');
			var kcId=$('#Classco').combobox('getValue');
			if(bjId2==0||kcId==0){
				$('#ClassGradeDiv').hide();
			}else{
				$('#ClassGradeDiv').show();
				shuaxin(bjId2,kcId);
				$('#ClassGradeTable').datagrid('clearSelections');
			}
	})	
}) 

$("input[name='ipt']").numberbox({
    min:0,
    precision:0
});
 
function xg(id,grade){
		if(!(/^[0-9]\d*$/.test(grade))){
			$.messager.alert('提示','请输入正整数','info');
			return;
		};
	$.post('grade/classCjxg',{id:id,grade:grade},function(data){
			if(data.success){
				$.messager.show({title:'提示',msg:data.msg});
			}else{
				$.messager.alert('提示',data.msg,'warning');
			}
		});
}

function shuaxin(bjId2,kcId){
	$('#ClassGradeTable').datagrid($.extend({},$.crudgrid.defaults,{
		url:'grade/page?bjId='+bjId2+"&kcId="+kcId,
		onLoadSuccess:function(data){
	            $("input[name='ipt']").numberbox({
	            	onChange:function(grade,oldgrade){
		            	var grid=$('#ClassGradeTable').datagrid('getSelected');
						xg(grid.id,grade);
		            }
		        });  
	   	},
		columns:[
			[
				{title:'学号',field:'stuNo',width:200,formatter:function(value,row,index){
	            		return row.student.stuNo;
					}
	           	},
				{title:'姓名',field:'name',width:300,formatter:function(value,row,index){
            		return row.student.name;
					}
				},
				{title:'成绩',field:'grade',width:200,formatter:function(value,row,index){
						if(!row.grade){
							row.grade=0;
						}
					   return '<input  name="ipt" value="'+row.grade+'">'
					}
				},
			]		
		],
		toolbar:['-',$.crudgrid.buttons.refrsh,'-']
	}))
}



	
</script>
<div class="easyui-panel" data-options="fit:true" title="班级成绩录入" style="display: flex;flex-direction: column;">
<p style="flex-grow: 0;">
	<span style="margin-left:10px ">选择班级：</span><select id="Classtb"class="easyui-combobox" data-options="
		editable:false,
		width:200,
		url:'tbclass/list',
		valueField:'id',
		panelHeight:200,
		textField:'name',
		icons: [{
			iconCls:'icon-clear',
       		handler: function(e){
        		$(e.data.target).textbox('clear');
        		$('#ClassGradeDiv').hide();
    			}
    		}]
	"></select>
	<span style="margin-left:10px ">选择课程：</span><select id="Classco" class="easyui-combobox" data-options="
		editable:false,
		width:200,
		panelHeight:200,
		url:'course/list',
		valueField:'id',
		textField:'name',
			icons: [{
			iconCls:'icon-clear',
       		handler: function(e){
        		$(e.data.target).textbox('clear');
        		$('#ClassGradeDiv').hide();
    			}
    		}]
		
	"></select>
	<a id="ClassGradebtn"  class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="margin-left: 10px">查询</a>
</p>
<div id="ClassGradeDiv" style="flex-grow: 1;"> 
	<table id="ClassGradeTable"></table>
</div>
</div>
